<!doctype html>
<html>
    <head>
        <title>easyXDM</title>
        <script type="text/javascript" src="../easyXDM.debug.js">
        </script>
        <script type="text/javascript">
            /**
             * Request the use of the JSON object
             */
            easyXDM.DomHelper.requiresJSON("../json2.js");
        </script>
        <script type="text/javascript">
            // this is only bootstrapping code
            var REMOTE = (function(){
                var remote = location.href;
                switch (location.host) {
                    case "provider.easyxdm.net":
                        location.href = remote.replace("provider", "consumer");
                        break;
                    case "easyxdm.net":
                        remote = remote.replace("easyxdm.net", "consumer.easyxdm.net");
                        break;
                    case "consumer.easyxdm.net":
                        remote = remote.replace("consumer", "provider");
                        break;
                    case "xdm1":
                        remote = remote.replace("xdm1", "xdm2");
                        break;
                }
                return remote.substring(0, remote.lastIndexOf("/"));
            }());
            
            // this is really what you are after
            var xhr = new easyXDM.Rpc({
                local: "../name.html",
                swf: REMOTE + "/../easyxdm.swf",
                remote: REMOTE + "/../cors/",
                remoteHelper: REMOTE + "/../name.html"
            }, {
                remote: {
                    request: {}
                }
            });
            
            function getGlossary(){
                xhr.request({
                    url: "../example/glossary.aspx",
                    method: "POST",
                    headers: {
                        "x-auth-token": "abcde"
                    },
                    data: {
                        param1: "a",
                        param2: "b"
                    }
                }, function(rpcdata){
                    var json = easyXDM.getJSONObject().parse(rpcdata.data);
                    
                    document.getElementById("response").innerHTML = json.glossary.title;
                    document.getElementById("header").innerHTML = rpcdata.headers["x-foo"];
                });
                
            }
        </script>
    </head>
    <body>
        <div style="border:1px solid black;padding:3px;margin:10px;">
            <a href="index.html">Index of examples</a>
            | <a href="http://github.com/oyvindkinsey/easyXDM/#readme">Readme at github</a>
            | 
            | <a href="http://easyxmd.net/">easyXDM.net</a>
            | <a href="http://groups.google.com/group/easyxdm">easyXDM at Google Groups</a>
            <br/>
            The examples are executing slower than the production build due to the extensive tracing.
            <br/>
            If you are alerted about a popup, then this is only the trace log feature. You can ignore this.
        </div>
        <script type="text/javascript">
            document.write("Domain: " + location.host);
        </script>
        <!-- easyXDM.Debug.trace(msg) will output its messages to any element with the id "log" -->
        <div id="log" style="height:100px;border:1px dotted black;overflow:auto">
        </div>
        <div id="embedded">
        </div>
        <div>
            This example shows how to use easyXDM to call regular ajax/cors services (no JSONP) from remote domains.
            <br/>
            <input type="button" onclick="getGlossary()" value="Call getGlossary using the exposed method"/>
            <br/>
            Data from response:<span id="response"></span>
            <br/>
            Data from header:<span id="header"></span>
        </div>
        <script type="text/javascript">
            var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
            document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
        </script>
        <script type="text/javascript">
            if (location.host.indexOf("easyxdm.net") !== -1) {
                try {
                    var pageTracker = _gat._getTracker("UA-9535591-3");
                    pageTracker._setDomainName(".easyxdm.net");
                    pageTracker._trackPageview();
                } 
                catch (err) {
                }
            }
        </script>
    </body>
</html>
